<?php

namespace Common\Taglib;

class cat
{
    public function run($attr)
    {
        $order = 'c_sort desc , c_id asc';
        $type  = $attr['type'];
        $pid   = $attr['pid'];
        $id    = intval($attr['id']);
        $field = trim($attr['field']);

        // 条件生成
        if ($id <> '') {
            $map['c_id'] = $id;
        } else {
            if ($pid !== '') {
                $map['c_pid'] = $pid;
            }
            if ($type != '') {
				if ($type=='question'){
				$type=1;
				}
				if ($type=='article'){
				$type=2;
				}
				if ($type=='bbs'){
				$type=3;
				}
                $map['c_type'] = intval($type);
            }
        }
		//dump($map);
        $list  = D('Category')->get_list($map, $order, $field);
        $count = count($list);

        return compact('list', 'count');
    }
}